Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How to remove the "selected" Attribute and move it to another option using Cypress?

I have tried:

cy.get(`div[class="input-group input-group-sm"] select[name="activeStatus"]`).find(":selected").invoke("removeAttr", "selected")

which doesn't work as I have hoped, but it's been the closest to it I think. Anyone have any tips? I want to move the "Selected" attribute from Active, to Cancelled.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're halfway there, the removal part works. To add selected to Cancelled, invoke attr

// remove
cy.get('select')
  .find(':selected')
  .should('contain', 'Active')
  .invoke('removeAttr', 'selected')

// add
cy.get('select')
  .find('option')
  .contains('Cancelled')
  .invoke('attr', 'selected', true)

//confirm
cy.get('select')
  .find(':selected')
  .should('contain', 'Cancelled')

This gives you

<option selected="selected">Cancelled</option>

If you prefer

<option selected>Cancelled</option>

use this instead

// add
cy.get('select')
  .find('option')
  .contains('Cancelled')
  .then($el => $el[0].setAttribute('selected', ''))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!